from html_telegraph_poster import TelegraphPoster
from rss_translator import NewsTranslator
import json


class Publicist:

    def __init__(self):
        self.r = NewsTranslator()
        self.cfg = json.load(open('./tg_info.json', 'rb'))
        self.token = self.cfg['access_token']
        self.author = "NextCloud"

    async def page_designer(self):
        links = []
        data = await self.r.feed_translator()

        for i in data:
            tg_en = TelegraphPoster(self.token)
            en_post = tg_en.post(
                    author=self.author,
                    title=i['title'],
                    text=i['content']
            )
            tg_ru = TelegraphPoster(self.token)
            ru_post = tg_ru.post(
                author=self.author,
                title=i['ru_title'],
                text=i['ru_content']
            )
            double_link = {'original_link': i['link'],
                           'en_post': en_post['url'],
                           'ru_post': ru_post['url']}

            links.append(double_link)

        print(links)
